<?PHP
// vim: set expandtab tabstop=4 shiftwidth=4:
// +----------------------------------------------------------------------+
// | SAPID CMS                               		  					  |
// +----------------------------------------------------------------------+
// | Author:  Dmitry Sheiko (www.cmsdevelopment.com)	                  |
// | Copyright (c) 2004 Dmitry Sheiko	                                  |
// | http://sapid.sourceforge.net	                                      |
// +----------------------------------------------------------------------+
// | This source file is free software; you can redistribute it and/or    |
// | modify it under the terms of the GNU Lesser General Public           |
// | License as published by the Free Software Foundation; either         |
// | version 2.1 of the License, or (at your option) any later version.   |
// |                                                                      |
// | This source file is distributed in the hope that it will be useful,  |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    |
// | Lesser General Public License for more details.                      |
// +----------------------------------------------------------------------+
// Release: 08.11.04 (dd/mm/yy)
// $Id: edit.php,v 1.4 2006/02/20 08:39:46 sheiko Exp $
session_start();
if(!isset($_SESSION["user"]["LOGIN"]) or $_SESSION["user"]["NOLOGIN"]!="") die();

//Cut off lost picture requests
if (preg_match("/\.[gjpi][ipnc][fgo]/i", $_SERVER['REQUEST_URI'])) exit;
include ("../../etc/rc.conf.php");
if (!defined("SAPID_STARTED")) die("Hacking attempt!");
//		$root_path = preg_replace("/usr\/system\/edit\.php$/is", "", $_SERVER["SCRIPT_FILENAME"])."/";
//		$root_path = preg_replace("/\/\//is","/", $root_path);
include(ROOT_PATH . "etc/rc.d/debug.inc.php");
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?=$default_charset?>" />
<link rel="stylesheet" type="text/css" href="<?=$env["http_path"]?>/usr/system/light.css">
<title>Code editor</title>

<SCRIPT LANGUAGE="JavaScript">
<!--
function viewObject(name)
{
 var obj = eval(name), i;

 if(!obj)  {
   alert(name + " is not an object");
   return;
 }

 var w_Test = open("","Test","width=600,height=500,scrollbars=1");

 if(!w_Test)  {
   alert("Cannot open window for "+name);
   return;
 }

 w_Test.document.open();

 for(i in obj)
   w_Test.document.write(name+"."+i+"="+obj[i]+"<br>");

 w_Test.document.close();
}

function getCursorPos(obj) {
	obj.focus();
	var sel=obj.document.selection.createRange();
	sel.moveStart('textedit',-1);
	return sel.text.length;
}

function CodeJustify() {
	var arr = new Array();
	var sarr = new Array();

	re = /<(.*?)[\s>]/ig;
	sarr = document.edit.code.value.match(re);

	for(i=0;i<sarr.length;i++) {
		re = /^.*?<(.*?)[\s>].*?$/i;
		tag = sarr[i].replace(re, "$1");
		//document.writeln(tag);
	}

}

// -->
</SCRIPT>

<SCRIPT LANGUAGE="JavaScript" FOR="Ok" EVENT="onclick">
<!--
  var arr = new Array();
  arr["code"] = document.edit.code.value;
  window.returnValue = arr;

  obj = document.getElementById('code');
  arr["NewPos"] = getCursorPos(obj);

  window.close();
// -->
</SCRIPT>

<SCRIPT LANGUAGE="JavaScript" FOR="window" EVENT="onload">
<!--
document.edit.code.value = window.dialogArguments["code"];
if(window.dialogArguments["CursorPos"]) {
	obj = document.getElementById('code');
	if (obj.createTextRange) {
	 var r = obj.createTextRange();
	 r.collapse(true);
	 r.moveStart('character', window.dialogArguments["CursorPos"]-1);
	 r.moveEnd('character', window.dialogArguments["InnerLen"]);
	 r.select();
	}
}
// -->
</SCRIPT>
</head>
<body style="margin: 0px; padding: 5px 5px 5px 5px; background: #CEE4F2;">
<form name="edit"  style="margin: 0px; padding: 0px;">
<textarea id="code" rows="12" style="height: 520px; width: 100%; border: 1px solid #003263; padding: 5px 5px 5px 5px; <?PHP print ($SystemTextAreaStyle ? $SystemTextAreaStyle : "background-color: white; font-family: Courier new, Tahoma, Arial; font-size: 12px;"); ?>" name="code"></textarea>
<table width="100%" cellpadding="0" cellspacing="0">
	<tr>
		<td valign="top"  align="left">
		<!-- <input class="sapidcms_cont_btn" type="button" onClick="CodeJustify();" value=" Justify "> -->
		</td>
		<td valign="top" align="right">
            <input class="sapidcms_cont_btn" type="button" id="Ok" value=" Save ">
            <input class="sapidcms_cont_btn" type="button" onClick="window.close();" value=" Cancel ">
		</td>
	</tr>
</table>
</form>
</body>
</html>